/*
 * UMediaPacket.h
 *
 *  Created on: 2020年3月26日
 *      Author: chuanjiang.zh
 */

#ifndef UMEDIAPACKET_H_
#define UMEDIAPACKET_H_

#include "UMediaType.h"

struct AVPacket;


class DLLEXPORT UMediaPacket
{
public:
	UMediaPacket();
	virtual ~UMediaPacket();

	UMediaPacket(const UMediaPacket& obj);
	UMediaPacket& operator = (const UMediaPacket& obj);

	void reset();

	UMediaPacket clone();

	UMediaPacket& clone(const UMediaPacket& obj);

	AVPacket* get();
	const AVPacket* get() const;

	explicit UMediaPacket(AVPacket* avpkt);
	UMediaPacket& operator = (AVPacket* avpkt);
	UMediaPacket& ref(AVPacket* avpkt);
	UMediaPacket& clone(AVPacket* avpkt);

	uint8_t * data();
	int size() const;
	uint8_t * data() const;

	int64_t pts() const;
	int64_t dts() const;
	int stream_index() const;
	int flags() const;
	int duration() const;
	int64_t pos() const;

	void set_pts(int64_t val);
	void set_dts(int64_t val);
	void set_stream_index(int val);
	void set_flags(int val);
	void set_duration(int val);
	void set_pos(int64_t val);

	void setData(uint8_t* data, int size);

	int copy(const AVPacket *src);

	void copy(const uint8_t* data, int size);

	int grow(int grow_by);

	void shrink(int size);

	int newPacket(int size);

	void freePacket();

	int type() const;

	void set_type(int val);

	bool isVideo() const;
	bool isAudio() const;
    bool isAV() const;

	bool isKey() const;

    bool isVideoKey() const;

	bool isEmpty() const;

	int refTo(AVPacket* dst);

	int assignTo(AVPacket* dst);

	int copy_props(const AVPacket* src);
	int copy_props(const UMediaPacket& src);

	void set_size(int size);

protected:
	void cleanup();

protected:
	AVPacket*	m_avpkt;
	//int	m_type;


};

#endif /* UMEDIAPACKET_H_ */
